local zhanwei = fk.CreateSkill{
    name = "xiaobai__zhanwei",
}
Fk:loadTranslationTable{
    ["xiaobai__zhanwei"] = "斩威",
    [":xiaobai__zhanwei"] = "出牌阶段，你可以弃置X张伤害牌并对一名其他角色造成1点伤害。然后若其为体力值最大的角色，你可以对其使用任意张以此法弃置的牌（X为其已损失的体力值+1）。",
    ["#xiaobai__zhanwei"] = "斩威：弃置伤害牌，对一名符合条件的其他角色造成伤害",
    ["#xiaobai__zhanwei-shubian"] = "斩威：你可以用 %dest 的手牌，对其发动“斩威”",
    ["#xiaobai__zhanwei-use"] = "斩威：你可以对 %dest 使用任意张以此法弃置的牌",
}

zhanwei:addEffect("active", {
    prompt = function (self, player, selected_cards, selected_targets)
        if player.phase == Player.Finish then
            return "#xiaobai__zhanwei-shubian::"..self._extra_data.xiaobai__shubian
        else
            return "#xiaobai__zhanwei"
        end
    end,
    min_card_num = 1,
    target_num = 1,
    card_filter = function(self, player, to_select)
        if player.phase == Player.Finish then
            return not player:prohibitDiscard(to_select) and Fk:getCardById(to_select).is_damage_card and table.contains(self._extra_data.cardIds, to_select)
        else
            return not player:prohibitDiscard(to_select) and Fk:getCardById(to_select).is_damage_card
        end
    end,
    target_filter = function(self, player, to_select, selected, selected_cards)
        if player.phase == Player.Finish then
            return #selected == 0 and to_select.id == self._extra_data.xiaobai__shubian and to_select:getLostHp() + 1 == #selected_cards
        else
            return #selected == 0 and to_select ~= player and to_select:getLostHp() + 1 == #selected_cards
        end
    end,
    expand_pile = function (self, player)
        if player.phase == Player.Finish then
            if self._extra_data.xiaobai__shubian ~= player.id then
                return self._extra_data.expandPile
            else
                return {}
            end
        else
            return {}
        end
    end,
    on_use = function(self, room, effect)
        local player = effect.from
        local target = effect.tos[1]
        local cards = table.simpleClone(effect.cards)
        local current = player
        if room:getCardOwner(effect.cards[1]) then
            current = room:getPlayerById(room:getCardOwner(effect.cards[1]).id)
        end
        room:throwCard(effect.cards, zhanwei.name, current, player)
        if not target.dead then
            room:damage{
                from = player,
                to = target,
                damage = 1,
                skillName = zhanwei.name,
            }
        end
        if not target.dead and table.every(room.alive_players, function(p)
            return p.hp <= target.hp
        end) then
            while true do
                local use = room:askToUseRealCard(player, {
                    pattern = cards,
                    expand_pile = cards,
                    skill_name = zhanwei.name,
                    cancelable = true,
                    extra_data = {
                        bypass_distances = true,
                        bypass_times = true,
                        extraUse = true,
                        exclusive_targets = {target.id},
                    },
                    prompt = "#xiaobai__zhanwei-use::"..target.id
                })
                if use then
                    table.removeOne(cards, use.card.id)
                else
                    break
                end
            end
        end
    end,
})

return zhanwei